<?php

namespace app\Http\Controllers\Admin;

use Tinywan\Storage\Storage;

class MediaController
{

    use Tool;
    public function upload()
    {
        $res = Storage::uploadFile();
        return $this->successWithData($res);
    }

    public function uploadImg()
    {


        $file = request()->file('file');
        $host = request()->host();
        if ($file && $file->isValid()) {
            $fileName = uuid().'.'.$file->getUploadExtension();
            $file->move(public_path().'/img/'.$fileName);
            $url = getenv('APP_URL').'/img/'.$fileName;
            return json([
                  "url" => $url
            ]);
        }
        return json(['code' => 1, 'msg' => 'file not found']);
    }

//    // 导入电子表格文件，返回为索引数组
//    Static public function uploadXlsxArray()
//    {
//
//        $file = request()->file('file');
//        $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file->getPathname());
//        $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, false);
//        return $sheetData;
//    }
//
//    // 返回为关联数组
//    Static public function uploadXlsxObject(){
//        $file = request()->file('file');
//        $excel = new \Rap2hpoutre\FastExcel\FastExcel();
//        $collection = $excel->import($file->getPathname());
//        $arrData = $collection->toArray();
//        return $arrData;
//    }


}